package com.sfac.springCloudAccount.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.springCloudAccount.service.UserService;
import org.example.account.entity.User;
import org.example.account.vo.UserVo;
import org.example.common.vo.Result;
import org.example.common.vo.Search;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jzq
 * @date 2022/8/27 11:11
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/api/account")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * localhost/api/login ---- post
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/login", consumes = "application/json")
    public Result<User> login(@RequestBody User user) {
        return userService.login(user);
    }

    /**
     * localhost/api/user ---- post
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/user", consumes = "application/json")
    public Result<User> insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    /**
     * localhost/api/user ---- put
     *
     * @param user
     * @return
     */
    @PutMapping(value = "/user", consumes = "application/json")
    public Result<User> updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    /**
     * localhost/api/user/1 ---- get
     *
     * @param id
     * @return
     */
    @GetMapping("/user/{id}")
    public User getUserById(@PathVariable int id) {
        return userService.getUserById(id);
    }

    /**
     * localhost/api/user/1 ---- delete
     *
     * @param id
     * @return
     */
    @DeleteMapping("/user/{id}")
    public Result<Object> deleteUserById(@PathVariable int id) {
        return userService.deleteUserById(id);
    }

    /**
     * localhost/api/users ---- post
     *
     * @param search
     * @return
     */
    @PostMapping(value = "/users", consumes = "application/json")
    public PageInfo<User> getUsersBySearchBean(@RequestBody Search search) {
        return userService.getUsersBySearchBean(search);
    }


    /**
     * localhost/api/userVo/1/1890 ---- get
     */
    @GetMapping("/userVo/{userId}/{cityId}")
    public UserVo getUserVoBy(@PathVariable int userId, @PathVariable int cityId) {
        return userService.getUserVoByUserIdAndCityId(userId, cityId);
    }


}

